<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>知识库管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="icon" type="image/x-icon" href="/static/img/favicon.ico">
		<!-- jQuery-->
		<script type="text/javascript" src="/static/plugins/jquery/jquery-3.6.0.min.js"></script>

		<!-- layui-->
		<link rel="stylesheet" href="/static/plugins/layui/2.8.4/css/layui.css" media="all">
		<script src="/static/plugins/layui/2.8.4/layui.js" charset="utf-8"></script>

		<!-- 页面样式-->
		<link rel="stylesheet" href="/static/css/eKnow/knowledgeBase.css" media="all">

	</head>
	<style>
		.list-span{
			white-space: pre-line;
			text-overflow:ellipsis;/*设置隐藏部分为省略号*/
			overflow: hidden;/*设置隐藏*/
			display: -webkit-box;
			-webkit-line-clamp: 4;
			-webkit-box-orient: vertical;
		}
	</style>
	<body style="background-color: #F7F7F9;">
		
		<!--标题-->
		<div class="title-view">
			<div class="title-main"><span>知识库管理</span></div>
			<div class="title-tip">
				<span>什么是知识库？</span><br>
				<span>可以把AI看作一个人，而知识库则是它手边的一份资料。当你问它问题时，它会参考这份资料进行回答。</span><br>
				<span>在数据规模不断增长、算力日益珍贵的现状下，知识库可作为AI大模型的「超级大脑」，打一份小抄，相对较低的成本补充动态知识。</span>
				<span>知识库可以减少AI大模型的幻觉和错误回答，大模型在回答问题时可以依靠知识库进行判断和回答，减少产生幻觉的可能性。</span>
				<span>AI大模型的训练和调优需要消耗大量的计算资源，而知识库可以在不需要对模型进行调优的情况下保证模型回答结果的专业性。</span>
				<span>AI大模型的训练和调优需要时间成本，而知识库可以实时补充现有模型通用知识，这样可以确保回答的准确性和时效性。</span>
			</div>
		</div>

		<!--内容-->
		<div class="content-view">
			<!--内容顶部按钮-->
			<div class="btn-view">
				<div class="layui-btn-container">
				   <button type="button" class="layui-btn layui-bg-blue btn-view" lay-on="add-iframe"><i class="layui-icon layui-icon-add-1"></i>新增知识库</button>
				   
				   <div class="layui-input-group btn-view-search">
				        <input type="text" placeholder="搜索知识库名称" class="layui-input" id="nameInput">
				        <div class="layui-input-split layui-input-suffix" style="cursor: pointer;" onclick="searchName();">
							<i class="layui-icon layui-icon-search"></i>
				        </div>
				    </div>
				</div>
			</div>

			<!--内容列表-->
			<div class="layui-bg-white" style="padding: 16px;">
			  <div class="layui-row layui-col-space15" id="knowledgeList">
				  <!--
				<div class="layui-col-md3">
				    <div class="layui-card card-view" onclick="toListPage()" >
						<div class="layui-card-header">客服AI知识库
							<div class="more-set">
								<button class="layui-btn layui-btn-primary demo-dropdown-on more-btn-set" lay-options="{trigger: 'hover'}">
								    <i class="layui-icon layui-icon-more"></i>
								  </button>
							</div>
						</div>
						<div class="layui-card-body card-body-set">运营问答相关，提供实时陪伴式运营</div>
				    </div>
				</div>-->
			  </div>
			</div>


		</div>


		<script type="text/javascript">
			$(function() {
				getKnowledgeBaseList("");
				setDropdown();

			});

			//获取知识库列表信息
			function getKnowledgeBaseList(knowledgeName){
				$.ajax({
					url: '/api/inter/knowledgeBase/getKnowledgeBaseList',
					data: {'knowledgeName':knowledgeName},
					type: 'POST',
					async: false,
					success: function (result) {
						layer.close();
						console.log('result:',result);
						if(result.code=='SUCCESS'){
							var knowledgeList = result.knowledgeList;
							if(knowledgeList!=null && knowledgeList.length>0){
								var htmlStr = '';
								for(var i=0;i<knowledgeList.length;i++){
									 htmlStr += '<div class="layui-col-md3">' +
											' <div class="layui-card card-view" onclick="toListPage('+knowledgeList[i].id+')" >' +
											'   <div class="layui-card-header">' + knowledgeList[i].knowledgeBaseName +
											'   <div class="more-set">' +
											'   	<button class="layui-btn layui-btn-primary demo-dropdown-on more-btn-set" ' +
											' lay-options="{trigger: \'hover\',data: [{title: \'修改\', id: '+knowledgeList[i].id+'},{title: \'删除\', id: '+knowledgeList[i].id+'}]}" id="'+knowledgeList[i].id+'">' +
											'     		<i class="layui-icon layui-icon-more"></i>' +
											'   	</button>' +
											'   </div>' +
											'   </div>' +
											' <div class="layui-card-body card-body-set"><span class="list-span"></span>'+knowledgeList[i].knowledgeBaseDescribe+'</div>' +
											' </div>' +
											'</div>';
								}
								$('#knowledgeList').html(htmlStr);
							}else {
								$('#knowledgeList').html('<div class="layui-col-md12" style="width: 100%; text-align:center;">暂无知识库信息</div>');
							}
							setDropdown();
						}else {//失败
							layer.close();
							layer.msg('不好意思，系统出现问题了，请稍后重试！', {icon: 2});
						}
					},
					error: function () {
						layer.close();
						layer.msg('不好意思，系统出现问题了，请稍后重试！', {icon: 2});
					}
				});
			}
			//查询按钮
			function searchName() {
				layui.layer.msg('加载中', {icon: 16,shade: 0.01});
				var nameInput = $('#nameInput').val();
				getKnowledgeBaseList(nameInput==null?'':nameInput);
				setDropdown();
			}

			//跳转新增、修改页面
			function toAddOrUpdate(knowledgeBaseId,addOrUpdate) {
				layer.open({
					title: (addOrUpdate=='add'?'新增':'修改'),
					type: 2,
					area: ['1000px', '600px'],
					content: '/web/eKnowAi/webEKnowAiController/knowledgeBaseAdd?knowledgeBaseId='+knowledgeBaseId + '&addOrUpdate='+addOrUpdate,
					fixed: false, // 不固定
					maxmin: true,
					btnAlign: 'c',

				});
			}

			function setDropdown() {
				layui.use(function(){
					var dropdown = layui.dropdown;
					var $ = layui.$;
					var layer = layui.layer;
					var util = layui.util;
					// 自定义事件
					dropdown.render({
						elem: '.demo-dropdown-on',
						click: function(obj){
							if(obj.title=='修改'){
								toAddOrUpdate(obj.id,"update");
							}else {
								delBase(obj.id);
							}
						}
					});
					// 事件
					util.on('lay-on', {
						'add-iframe': function(){
							layer.open({
								title: '新增',
								type: 2,
								area: ['1000px', '600px'],
								content: '/web/eKnowAi/webEKnowAiController/knowledgeBaseAdd?knowledgeBaseId=11111&addOrUpdate=add',
								fixed: false, // 不固定
								maxmin: true,
								btnAlign: 'c',

							});
						},
					})
				});
			}


			function delBase(id) {
				layer.confirm('确定要删除知识库?', {icon: 3}, function () {
					//点击确定的回调
					layui.layer.msg('请稍后', {
						icon: 16,
						shade: 0.01
					});
					delBaseYes(id);
				}, function () {});//点击取消的回调

			}


			function delBaseYes(id){
				$.ajax({
					url: '/api/inter/knowledgeBase/delOrUpdateKnowledgeBase',
					data: {
						'id':((id!=null &&id!='')?id:'')
					},
					type: 'POST',
					async: true,
					success: function (result) {
						if(result.code=='SUCCESS'){
							layer.close();
							layer.msg("操作成功", {icon: 1});
						}else if(result.code=='CANNOT'){
							layer.close();
							layer.alert('此知识库中的资料不为空，无法删除。若要删除，请先清空该知识库！', {
								icon: 0,
								shadeClose: true,
								title: '提示 '
							})
						}else if(result.code=='HASSCENE'){
							layer.close();
							layer.alert('此知识库已被场景绑定，无法删除。若要删除，请先解绑！', {
								icon: 0,
								shadeClose: true,
								title: '提示 '
							})
						}else if(result.code=='HASTYPENODEL'){
							layer.close();
							layer.alert('此知识库中还有分类信息，无法删除。若要删除，请先清空该知识库的分类！', {
								icon: 0,
								shadeClose: true,
								title: '提示 '
							})
						}else {//失败
							layer.close();
							layer.msg("删除失败，请稍后再试！", {icon: 2});
						}
					},
					error: function () {
						layer.close();
						layer.msg("删除失败，请稍后再试！", {icon: 2});
					}
				});


			}


		function toListPage(id){
			//window.top.xadmin.add_tab("知识库详情","/web/eKnowAi/webEKnowAiController/knowledgeBaseList");
			layer.open({
				type: 2,
				offset: 'r',
				anim: 'slideLeft', // 从右往左
				title: false,
				area: ['100%', '100%'],
				shade: 0.1,
				shadeClose: false,
				closeBtn:0,
				content: '/web/eKnowAi/webEKnowAiController/knowledgeBaseList?id='+id
			});
		}
		</script>
		
	</body>
</html>


